﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess.Entity;
using ExaminationSys.Helper;
using Ext.Net;


namespace ExaminationSys.View.Paper
{
    public partial class PaperInfoSearchWindow : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public Store GridStore { get; set; }
        public static Action<PageEntity> SearchFun;

        public void Show(Action<PageEntity> _SearchFun)
        {
            SearchFun = _SearchFun;
            this.PaperInfoSearch.Show();

        }

        protected void SearchPaperInfo(object sender, DirectEventArgs e)
        {
            string sqlWhere = " 1= 1 ";
            if (!string.IsNullOrWhiteSpace(PaperInfoTitle.Text))
            {
                var title = PaperInfoTitle.Text;
                title = title.SqlSafe();

                //标题
                if (string.IsNullOrEmpty(title))
                {
                    sqlWhere += string.Format(" AND Title like '%{0}%' ", title);
                }

                //栏目
                //if (SectionID.SelectedItem != null)
                //{
                //    sqlWhere += string.Format("and SectionID = '{0}' ", new Guid(SectionID.SelectedItem.Value));
                //}

                //阶段
                if(RadioHeight.Checked){
                    sqlWhere += string.Format("and Level = 1 ");
                }
                if(RadioMiddle.Checked){
                    sqlWhere += string.Format("and Level = 2 ");
                }
                if(RadioOriginal.Checked){
                    sqlWhere += string.Format("and Level = 3 ");
                }

                //难度
                if (DegreeCheckHight.Checked)
                {
                    sqlWhere += string.Format("and Degree = 1 ");
                }
                if (DegreeCheckMiddle.Checked)
                {
                    sqlWhere += string.Format("and Degree = 2 ");
                }
                if (DegreeCheckLow.Checked)
                {
                    sqlWhere += string.Format("and Degree = 3 ");
                }

                //类型
                if (RadTypeFixied.Checked)
                {
                    sqlWhere += string.Format("and Type = 1 ");
                }
                if (RadTypeAuto.Checked)
                {
                    sqlWhere += string.Format("and Type = 2 ");
                }

                //备注
                if (string.IsNullOrEmpty(Description.Text))
                {
                    sqlWhere += string.Format(" AND  Description '%{0}%' ", Description.Text);
                }
               
            }

           

          


            PageEntity pageEntity = new PageEntity();
            pageEntity.SqlWhere = sqlWhere;
            SearchFun.Invoke(pageEntity);
            GridStore.Reload();
            PaperInfoSearch.Hide();
        }
    }
}